import urllib.request
import urllib.parse


def create_request(pageIndex):
    url = "https://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=cname"
    params = {
        "cname": "北京",
        "&pid": "",
        "pageIndex": f"{pageIndex}",
        "pageSize": "10"
    }
    return urllib.request.Request(url, data=urllib.parse.urlencode(params).encode("utf-8"),
                                     headers={'User-Agent': 'Mozilla/5'})

def get_content(request):
    response = urllib.request.urlopen(request)
    content = response.read().decode('utf-8')
    return content


if __name__ == '__main__':
    for i in range(10):
        request = create_request(i + 1)
        content = get_content(request)
        print(content)
